package marksys.free.com.marksys.ui.face.facebykomlinplus;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;

import marksys.free.com.marksys.R;
import marksys.free.com.marksys.ui.face.facebykomlinplus.callback.FaceDetectionCallBack;

public class FaceSurfaceView extends FrameLayout {


    public FaceSurfaceView(@NonNull Context context) {
        super(context);
        initData(context);
    }

    public FaceSurfaceView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initData(context);
    }

    public FaceSurfaceView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initData(context);
    }
    CameraSurfaceView surfaceView;
    void initData(@NonNull Context context){
        LayoutInflater.from(context).inflate(R.layout.face_view_plus,this);
        surfaceView = findViewById(R.id.surfaceView);
        FaceView faceView = findViewById(R.id.faceView);

        surfaceView.faceView=faceView;
        surfaceView.handler = handler;
    }

    public void setFaceDetectionCallBack(FaceDetectionCallBack faceDetectionCallBack) {

        if (surfaceView != null){
            surfaceView.faceDetectionCallBack = faceDetectionCallBack;
        }
    }
    @SuppressLint("HandlerLeak")
    private Handler handler= new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            ImageView bitmap = findViewById(R.id.bitmap);
            bitmap.setImageBitmap((Bitmap) msg.obj);
        }
    };

}